//
//  ZyaDepositFlowVC.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2020/3/31.
//  Copyright © 2020 zwb. All rights reserved.
//

import UIKit

class ZyaDepositFlowVC: UITableViewController {

    @IBOutlet weak var deposit: UILabel!
    var depositStr = ""
    var dataArray = [ZyaCashFlowModel]()
    var page = 1
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "资金流水"
        self.tableView.rowHeight = 65
             tableView.tableFooterView = UIView()
        deposit.text = depositStr
            
            tableView.mj_header = KSRefreshHeader {
                self.page = 1
                self.network()
            }
            tableView.mj_footer = KSRefreshFooter {
                self.page += 1
                self.network()
            }
            tableView.mj_header?.beginRefreshing()
        
    }
 
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return self.dataArray.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        guard let cell = tableView.dequeueReusableCell(withIdentifier: ZyaDepositFlowCell.identifier, for: indexPath) as? ZyaDepositFlowCell else {
            fatalError("cell error")
        }
        let one = self.dataArray[indexPath.row]
        cell.one = one
        return cell
    }

    
    func network () {
        KSNetwork.shared.doRequest(API.queryCashFlowList(page: "\(self.page)", size: "10"),showHud: false) { (data:BaseResult<ZyaCashFlowModel>) in
              
              if data.flag == TRUE {
                  if let infos = data.infos {
                    if self.page == 1 {
                      self.dataArray.removeAll()
                    }
                      
                      self.dataArray += infos
                      
                      
                      
                      self.tableView.mj_header?.endRefreshing()
                      if infos.count < 10 {
                          self.tableView.mj_footer?.endRefreshingWithNoMoreData()
                      } else {
                          self.tableView.mj_footer?.endRefreshing()
                      }
                      self.tableView.reloadData()
                      
                  }
                  
              } else {
                  KSToast(data.message)
                  self.tableView.mj_footer?.endRefreshing()
              }
              
              
          }
          
      }
  

}
